package com.woniuxy.propertyjava.service.impl;


import com.woniuxy.propertyjava.dao.StaffDao;
import com.woniuxy.propertyjava.entity.Cartype;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Staff;
import com.woniuxy.propertyjava.service.StaffService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Staff)表服务实现类
 *
 * @author makejava
 * @since 2022-07-06 10:08:17
 */
@Service("staffService")

public class StaffServiceImpl implements StaffService {

    @Resource(type = StaffDao.class)
    StaffDao staffDao;

    @Override
    public Staff queryById(Integer staffid) {
        Staff staff = staffDao.queryById(staffid);
        return staff;
    }

    @Override
    public PageBean<Staff> getStaffPageBean(Staff staff, int pageIndex, int pageSize) {
        PageBean<Staff> pageBean = new PageBean<>();
        pageBean.setBeanList(staffDao.selectStaffsByStaffProperty(staff, pageIndex, pageSize));
        pageBean.setPageSize(pageSize);
        pageBean.setPageIndex(pageIndex);
        pageBean.setTotalRecode(staffDao.count(staff));
        return pageBean;
    }

    @Override
    public void inserStaff(Staff staff) {
        staffDao.insert(staff);
    }

    @Override
    public void updateStaff(Staff staff) {
        staffDao.update(staff);
    }

    @Override
    public void deleteStaff(int staffId) {
        staffDao.deleteById(staffId);
    }

    @Override
    public int getStaffIdByName(String staffName) {
        int staffid=staffDao.getIdByName(staffName);
        return staffid;
    }



    @Override
    public PageBean<Staff> queryByPage(Staff staff, int pageIndex,int pageSize) {
        long total = this.staffDao.count(staff);
        PageBean<Staff> pageBean = new PageBean<>();
        pageBean.setBeanList(staffDao.queryAllByLimit(staff,pageIndex,pageSize));
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecode((int)total);
        return pageBean;
    }


    @Override
    public Staff insert(Staff staff) {
        this.staffDao.insert(staff);
        return staff;
    }


    @Override
    public Staff update(Staff staff) {
        this.staffDao.update(staff);
        return this.queryById(staff.getStaffid());
    }


    @Override
    public boolean deleteById(Integer staffid) {
        return this.staffDao.deleteById(staffid) > 0;
    }
}

